package com.yyfax.ph.personal.entrydetail;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.aspsine.irecyclerview.IViewHolder;
import com.yyfax.common.recyclerview.BaseRecycleAdapter;
import com.yyfax.ph.R;

import java.util.List;


/**
 * 进件明细adapter
 * Created by zhangxian on 2017/11/4.<br>
 * Copyright 2017 www.yylending.com. All Rights Reserved.<br><br>
 */
public class EntryDetailAdapter extends BaseRecycleAdapter<EntryDetailModel.EntryDetailBean> {

	public EntryDetailAdapter() {
		super();
	}

	public EntryDetailAdapter(List<EntryDetailModel.EntryDetailBean> data) {
		super(data);
	}

	@Override
	public int getItemCount() {
		return getCount();
	}

	@Override
	public void onBindViewHolder(IViewHolder holder, int position) {
		EntryDetailAdapter.ViewHolder view = (EntryDetailAdapter.ViewHolder) holder;
		final EntryDetailModel.EntryDetailBean bean = getDataSet().get(position);
		view.mBorrowerTv.setText(remove(bean.name.trim(), ' '));
		view.mRecommendDateTv.setText(bean.rcmdTime);
		view.mStatusTv.setText(bean.status);
	}

	@Override
	public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.entry_detail_item_layout, null);
		return new EntryDetailAdapter.ViewHolder(view);
	}

	private String remove(String resource, char ch) {
		StringBuilder buffer = new StringBuilder();
		int position = 0;
		char currentChar;
		while (position < resource.length()) {
			currentChar = resource.charAt(position++);
			if (currentChar != ch)
				buffer.append(currentChar);
		}
		return buffer.toString();
	}

	static class ViewHolder extends IViewHolder {
		@BindView(R.id.borrower_tv)
		TextView mBorrowerTv;
		@BindView(R.id.recommend_date_tv)
		TextView mRecommendDateTv;
		@BindView(R.id.status_tv)
		TextView mStatusTv;

		ViewHolder(View view) {
			super(view);
			ButterKnife.bind(this, view);
		}
	}
}
